<?php
/*
	首页
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
set_html('header','common/header-cms');
$return['pcd']=$_SESSION['pcd']?:array();
$_SESSION['area_code']=$_RQ['area_code']?:$_SESSION['area_code'];
$return['area_code']=$_SESSION['area_code'];
$this->model('model')->add_dayredfee();
if($_RQ['op']=='main'){
	$return['list']=array();
	$return['indexpai']=array();	
	$return['shopset'] = plugin('jy_weishop')->plugin_setting('shopset');
	$return['indexpai'][]=array('name'=>'coupon');
	$return['indexpai'][]=array('name'=>'goods');
	$return['setting']['pluginnav']=$return['pluginset']['bankuai'];
	$return['setting']['hdps']=$return['pluginset']['hdps'];
	//子分类
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$times=$this->times2;
	$times=$this->model('model')->get_times($times);
	if($times){
		$i=0;
		foreach($times as $key=>&$value){
			$params['timeids like']='%;'.trim($value['time']).';%';
			$goodsnum=pdo_count('jy_newpingfee_goods',$params,'id');
			if(!$goodsnum){
				unset($times[$key]);
			}
		}
	}
	//公告列表
	$notice_list = pdo_fetchall('SELECT * FROM ' . tablename('jy_weishop_notice') . ' WHERE uniacid=:uniacid AND status=1  ORDER BY id DESC limit 4', array(':uniacid' => $_SESSION['uniacid']));
	if($notice_list){
		foreach($notice_list as &$notice){
			$notice['createtime']=date('Y-m-d h:i',$notice['createtime']);
		}
	}
	//获取用户信息
	$return['extradata']=array();
	$return['user']=model('core/member')->basic($_SESSION['uid']);
	$return['login']=$_SESSION['uid']?1:2;
	$return['times']=$times;
	$return['params']['teamnum']=intval($_RQ['teamnum']);
	$return['params']['tid']=0;
	set_html('title',$return['pluginset']['title']?'首页-'.$return['pluginset']['title']:'首页-拼单商城');
	$return['sharedata']=array(
		'title'=>$return['pluginset']['share_title']?$return['pluginset']['share_title']:'首页-拼单商城',
		'desc'=>$return['pluginset']['share_desc']?$return['pluginset']['share_desc']:'拼单商城单商户版，主流经典拼单商城，拼着买，更便宜！',
		'link'=>custom_url('jy_newpingfee/index//fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>$return['pluginset']['share_image']?tomedia($return['pluginset']['share_image']):tomedia($return['pluginset']['icon'])
	);
	if(intval($_RQ['fromuser'])){
		$this->model('member')->checklogin();
		$this->model('member')->setfromuser();
	}
	if(empty($return['orderlist'])){
		$return['coupon_wait']=model('jy_weishop/task')->pop_coupon_wait();
		if(!$return['coupon_wait']){
			$return['coupon_hd']=model('jy_weishop/task')->pop_coupon_hd();
			if(!$return['coupon_hd']){
				$return['game_wait']=model('jy_weishop/task')->pop_game();
			}
		}
	}
	$return['params']=array('tid'=>100);
	exi($return);
}
if($_RQ['op']=='getarea'){
	//获取当前区域经销商
	$postdata=get_postdata();
	$pcd = $postdata['pcd'];
	if(!$pcd['province'] || !$pcd['city'] || !$pcd['district']){
		return false;
	}
	$_SESSION['pcd']=$pcd;	
	$return['store']=$this->model()->get_area_code($pcd);
	$return['store']['saletime']=date('Y-m-d',time());
	$gettime=$return['pluginset']['gettime']*24*3600+time();
	$return['store']['gettime']=date('Y-m-d',$gettime);
	$return['store']['members']=pdo_count('jy_weishop_member',array('area_code'=>$return['store']['area_code']),'id');
	$return['store']['salenum']=pdo_getsum('jy_weishop_order',array('area_code'=>$return['store']['area_code']),'ispay');
	$return['sharedata']=array(
		'title'=>$return['store']['title'].$return['pluginset']['title'],
		'desc'=>$return['pluginset']['desc'],
		'link'=>custom_url('jy_newpingfee/index//area_code='.$return['store']['area_code'].'&fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>ATTACHMENT_URL.$return['pluginset']['storelogo'],
	);
	exi($return);
}
if($_RQ['op']=='getlist'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'ignore'=>0);
	//我的团
	//先查询我的订单
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$teams=pdo_getslice('jy_newpingfee_goods',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($teams){
		foreach($teams as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['goods']=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']));
			if(!$item['goods']['id']){
				unset($teams[$k]);
			}
			$item['teamnum']=$this->setting['pai_num']?:3;
			if(substr($item['team_rate'],-1)=='%'){
				$money=intval($team['goods']['price']*substr($item['team_rate'],0,-1))/100;
			}else{
				$money=$item['team_rate'];
			}
			$item['team_fee']=price($money);
			$item['order']=pdo_get('jy_newpingfee_team_log',array('uniacid'=>$_SESSION['uniacid'],'team_id'=>$item['id'],'mid'=>$item['mid']));
		}
	}
	$return['list']=$teams;
	exi($return);
}
if($_RQ['op']=='getteamlist'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>0);
	$params['status']=intval($_RQ['status']);
	$return['params']['status']=intval($_RQ['status']);
	//我的团
	//先查询我的订单
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$teams=pdo_getslice('jy_newpingfee_team',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($teams){
		foreach($teams as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['goods']=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']));
			if(!$item['goods']['id']){
				unset($teams[$k]);
			}
			$item['teamnum']=$this->model('team')->getteamnum($team);
			$item['pai_fee']=$this->setting['pai_fee']*$item['goods']['price']/100;
			$item['pai_tuifee']=$this->setting['pai_tuifee']*$item['goods']['price']/100;
			$item['order']=pdo_get('jy_newpingfee_team_log',array('uniacid'=>$_SESSION['uniacid'],'team_id'=>$item['id'],'mid'=>$item['mid']));
		}
	}
	$return['list']=$teams;
	exi($return);
}
function style($id)
{
	switch ($id%7) {	
		case 0: return "style-brown";
		case 1: return 'style-red';
		case 2: return "style-pink";
		case 3: return "style-orange";
		case 4: return "style-green";
		case 5: return "style-blue";
		case 6: return "style-purple";
		case 7: return "style-brown";
		default: }
}
	
?>